﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Hr.DAL
{
    /// <summary>
    /// 数据访问类HR_Rel_Purview。
    /// </summary>
    public class HR_Rel_Purview
    {
        public HR_Rel_Purview()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(Guid RecodID)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main");
			StringBuilder strSql = new StringBuilder();
			strSql.Append("select count(1) from HR_Rel_Purview where RecodID=@RecodID ");
			DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "RecodID", DbType.Guid,RecodID);
			int cmdresult;
			object obj = db.ExecuteScalar(dbCommand);
			if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
			{
				cmdresult = 0;
			}
			else
			{
				cmdresult = int.Parse(obj.ToString());
			}
			if (cmdresult == 0)
			{
				return false;
			}
			else
            {
                return true;
            }
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Hr.Entity.HR_Rel_Purview model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into HR_Rel_Purview(");
            strSql.Append("RecodID,DepartID,TermsName,ViewPubHouse,ViewPrivHouse,ViewHideHouse,ViewPrivDemand,ViewRealCustomer,ViewFakeCustomer,EditPrimaryHouse,EditNormalHouse,DelTrace,CanProtect,CanLockHouse,ViewLockHouse,ViewChange,CanChangeConfirm,ViewEntrust,CanCancelTrust,UnCancelTrust,CanDelTrust,ViewWatching,EditWatching,EditKey,UseKey,EditKeyUsing,EditTrust,CancelLockHouse,ViewPrivCustomer,EditPubDemand,EditPrivDemand,ViewTelLog,ViewBusiness,ViewHrInfo,ViewHrChange,ViewAttendance,ViewVacation,ViewAnnualLeave,ViewUserLog,DelHouse,EditPubCustomer,EditPrivCustomer,ViewStock,IsControl,Addtime,ShiftPubCustomer,SetPubLevel,ViewCrossPubShareDemand,ViewPubShareDemand,ViewCrossPubShareCustomer,ViewPubShareCustomer,viewtrace,CanUploadPicture,CanDeletePicture,CanPublishHouse)");

            strSql.Append(" values (");
            strSql.Append("@RecodID,@DepartID,@TermsName,@ViewPubHouse,@ViewPrivHouse,@ViewHideHouse,@ViewPrivDemand,@ViewRealCustomer,@ViewFakeCustomer,@EditPrimaryHouse,@EditNormalHouse,@DelTrace,@CanProtect,@CanLockHouse,@ViewLockHouse,@ViewChange,@CanChangeConfirm,@ViewEntrust,@CanCancelTrust,@UnCancelTrust,@CanDelTrust,@ViewWatching,@EditWatching,@EditKey,@UseKey,@EditKeyUsing,@EditTrust,@CancelLockHouse,@ViewPrivCustomer,@EditPubDemand,@EditPrivDemand,@ViewTelLog,@ViewBusiness,@ViewHrInfo,@ViewHrChange,@ViewAttendance,@ViewVacation,@ViewAnnualLeave,@ViewUserLog,@DelHouse,@EditPubCustomer,@EditPrivCustomer,@ViewStock,@IsControl,@Addtime,@ShiftPubCustomer,@SetPubLevel,@ViewCrossPubShareDemand,@ViewPubShareDemand,@ViewCrossPubShareCustomer,@ViewPubShareCustomer,@viewtrace,@CanUploadPicture,@CanDeletePicture,@CanPublishHouse)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecodID", DbType.Guid, model.RecodID);
            db.AddInParameter(dbCommand, "DepartID", DbType.Guid, model.DepartID);
            db.AddInParameter(dbCommand, "TermsName", DbType.AnsiString, model.TermsName);
            db.AddInParameter(dbCommand, "ViewPubHouse", DbType.Boolean, model.ViewPubHouse);
            db.AddInParameter(dbCommand, "ViewPrivHouse", DbType.Boolean, model.ViewPrivHouse);
            db.AddInParameter(dbCommand, "ViewHideHouse", DbType.Boolean, model.ViewHideHouse);
            //db.AddInParameter(dbCommand, "ViewPubDemand", DbType.Boolean, model.ViewPubDemand);
            db.AddInParameter(dbCommand, "ViewPrivDemand", DbType.Boolean, model.ViewPrivDemand);
            db.AddInParameter(dbCommand, "ViewRealCustomer", DbType.Boolean, model.ViewRealCustomer);
            db.AddInParameter(dbCommand, "ViewFakeCustomer", DbType.Boolean, model.ViewFakeCustomer);
            db.AddInParameter(dbCommand, "EditPrimaryHouse", DbType.Boolean, model.EditPrimaryHouse);
            db.AddInParameter(dbCommand, "EditNormalHouse", DbType.Boolean, model.EditNormalHouse);
            db.AddInParameter(dbCommand, "DelTrace", DbType.Boolean, model.DelTrace);
            db.AddInParameter(dbCommand, "CanProtect", DbType.Boolean, model.CanProtect);
            db.AddInParameter(dbCommand, "CanLockHouse", DbType.Boolean, model.CanLockHouse);
            db.AddInParameter(dbCommand, "ViewLockHouse", DbType.Boolean, model.ViewLockHouse);
            db.AddInParameter(dbCommand, "ViewChange", DbType.Boolean, model.ViewChange);
            db.AddInParameter(dbCommand, "CanChangeConfirm", DbType.Boolean, model.CanChangeConfirm);
            db.AddInParameter(dbCommand, "ViewEntrust", DbType.Boolean, model.ViewEntrust);
            db.AddInParameter(dbCommand, "CanCancelTrust", DbType.Boolean, model.CanCancelTrust);
            db.AddInParameter(dbCommand, "UnCancelTrust", DbType.Boolean, model.UnCancelTrust);
            db.AddInParameter(dbCommand, "CanDelTrust", DbType.Boolean, model.CanDelTrust);
            db.AddInParameter(dbCommand, "ViewWatching", DbType.Boolean, model.ViewWatching);
            db.AddInParameter(dbCommand, "EditWatching", DbType.Boolean, model.EditWatching);
            db.AddInParameter(dbCommand, "EditKey", DbType.Boolean, model.EditKey);
            db.AddInParameter(dbCommand, "UseKey", DbType.Boolean, model.UseKey);
            db.AddInParameter(dbCommand, "EditKeyUsing", DbType.Boolean, model.EditKeyUsing);
            db.AddInParameter(dbCommand, "EditTrust", DbType.Boolean, model.EditTrust);
            db.AddInParameter(dbCommand, "CancelLockHouse", DbType.Boolean, model.CancelLockHouse);
            //db.AddInParameter(dbCommand, "ViewPubCustomer", DbType.Boolean, model.ViewPubCustomer);
            db.AddInParameter(dbCommand, "ViewPrivCustomer", DbType.Boolean, model.ViewPrivCustomer);
            db.AddInParameter(dbCommand, "EditPubDemand", DbType.Boolean, model.EditPubDemand);
            db.AddInParameter(dbCommand, "EditPrivDemand", DbType.Boolean, model.EditPrivDemand);
            db.AddInParameter(dbCommand, "ViewTelLog", DbType.Boolean, model.ViewTelLog);
            db.AddInParameter(dbCommand, "ViewBusiness", DbType.Boolean, model.ViewBusiness);
            db.AddInParameter(dbCommand, "ViewHrInfo", DbType.Boolean, model.ViewHrInfo);
            db.AddInParameter(dbCommand, "ViewHrChange", DbType.Boolean, model.ViewHrChange);
            db.AddInParameter(dbCommand, "ViewAttendance", DbType.Boolean, model.ViewAttendance);
            db.AddInParameter(dbCommand, "ViewVacation", DbType.Boolean, model.ViewVacation);
            db.AddInParameter(dbCommand, "ViewAnnualLeave", DbType.Boolean, model.ViewAnnualLeave);
            db.AddInParameter(dbCommand, "ViewUserLog", DbType.Boolean, model.ViewUserLog);
            db.AddInParameter(dbCommand, "DelHouse", DbType.Boolean, model.DelHouse);
            db.AddInParameter(dbCommand, "EditPubCustomer", DbType.Boolean, model.EditPubCustomer);
            db.AddInParameter(dbCommand, "EditPrivCustomer", DbType.Boolean, model.EditPrivCustomer);
            db.AddInParameter(dbCommand, "ViewStock", DbType.Boolean, model.ViewStock);
            db.AddInParameter(dbCommand, "IsControl", DbType.Boolean, model.IsControl);
            db.AddInParameter(dbCommand, "Addtime", DbType.DateTime, model.Addtime);
            db.AddInParameter(dbCommand, "ShiftPubCustomer", DbType.Boolean, model.ShiftPubCustomer);
            db.AddInParameter(dbCommand, "SetPubLevel", DbType.Boolean, model.SetPubLevel);
            db.AddInParameter(dbCommand, "ViewCrossPubShareDemand", DbType.Boolean, model.ViewCrossPubShareDemand);
            db.AddInParameter(dbCommand, "ViewPubShareDemand", DbType.Boolean, model.ViewPubShareDemand);
            db.AddInParameter(dbCommand, "ViewCrossPubShareCustomer", DbType.Boolean, model.ViewCrossPubShareCustomer);
            db.AddInParameter(dbCommand, "ViewPubShareCustomer", DbType.Boolean, model.ViewPubShareCustomer);
            db.AddInParameter(dbCommand, "viewtrace", DbType.Boolean, model.ViewTrace);
            db.AddInParameter(dbCommand, "CanUploadPicture", DbType.Boolean, model.CanUploadPicture);
            db.AddInParameter(dbCommand, "CanDeletePicture", DbType.Boolean, model.CanDeletePicture);
            db.AddInParameter(dbCommand, "CanPublishHouse", DbType.Boolean, model.CanPublishHouse);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Hr.Entity.HR_Rel_Purview model)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("update HR_Rel_Purview set ");
            strSql.Append("DepartID=@DepartID,");
            strSql.Append("TermsName=@TermsName,");
            strSql.Append("ViewPubHouse=@ViewPubHouse,");
            strSql.Append("ViewPrivHouse=@ViewPrivHouse,");
            strSql.Append("ViewHideHouse=@ViewHideHouse,");
            //strSql.Append("ViewPubDemand=@ViewPubDemand,");
            strSql.Append("ViewPrivDemand=@ViewPrivDemand,");
            strSql.Append("ViewRealCustomer=@ViewRealCustomer,");
            strSql.Append("ViewFakeCustomer=@ViewFakeCustomer,");
            strSql.Append("EditPrimaryHouse=@EditPrimaryHouse,");
            strSql.Append("EditNormalHouse=@EditNormalHouse,");
            strSql.Append("DelTrace=@DelTrace,");
            strSql.Append("CanProtect=@CanProtect,");
            strSql.Append("CanLockHouse=@CanLockHouse,");
            strSql.Append("ViewLockHouse=@ViewLockHouse,");
            strSql.Append("ViewChange=@ViewChange,");
            strSql.Append("CanChangeConfirm=@CanChangeConfirm,");
            strSql.Append("ViewEntrust=@ViewEntrust,");
            strSql.Append("CanCancelTrust=@CanCancelTrust,");
            strSql.Append("UnCancelTrust=@UnCancelTrust,");
            strSql.Append("CanDelTrust=@CanDelTrust,");
            strSql.Append("ViewWatching=@ViewWatching,");
            strSql.Append("EditWatching=@EditWatching,");
            strSql.Append("EditKey=@EditKey,");
            strSql.Append("UseKey=@UseKey,");
            strSql.Append("EditKeyUsing=@EditKeyUsing,");
            strSql.Append("EditTrust=@EditTrust,");
            strSql.Append("CancelLockHouse=@CancelLockHouse,");
            //strSql.Append("ViewPubCustomer=@ViewPubCustomer,");
            strSql.Append("ViewPrivCustomer=@ViewPrivCustomer,");
            strSql.Append("EditPubDemand=@EditPubDemand,");
            strSql.Append("EditPrivDemand=@EditPrivDemand,");
            strSql.Append("ViewTelLog=@ViewTelLog,");
            strSql.Append("ViewBusiness=@ViewBusiness,");
            strSql.Append("ViewHrInfo=@ViewHrInfo,");
            strSql.Append("ViewHrChange=@ViewHrChange,");
            strSql.Append("ViewAttendance=@ViewAttendance,");
            strSql.Append("ViewVacation=@ViewVacation,");
            strSql.Append("ViewAnnualLeave=@ViewAnnualLeave,");
            strSql.Append("ViewUserLog=@ViewUserLog,");
            strSql.Append("DelHouse=@DelHouse,");
            strSql.Append("EditPubCustomer=@EditPubCustomer,");
            strSql.Append("EditPrivCustomer=@EditPrivCustomer,");
            strSql.Append("ViewStock=@ViewStock,");
            strSql.Append("IsControl=@IsControl,");
            strSql.Append("ShiftPubCustomer=@ShiftPubCustomer,");
            strSql.Append("SetPubLevel=@SetPubLevel,");
            strSql.Append("ViewCrossPubShareDemand=@ViewCrossPubShareDemand,");
            strSql.Append("ViewPubShareDemand=@ViewPubShareDemand,");
            strSql.Append("ViewCrossPubShareCustomer=@ViewCrossPubShareCustomer,");
            strSql.Append("ViewPubShareCustomer=@ViewPubShareCustomer,");
            strSql.Append("viewtrace=@viewtrace,");
            strSql.Append("CanUploadPicture=@CanUploadPicture,");
            strSql.Append("CanDeletePicture=@CanDeletePicture,");
            strSql.Append("CanPublishHouse=@CanPublishHouse,");
            strSql.Append("Addtime=@Addtime");
            strSql.Append(" where RecodID=@RecodID ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecodID", DbType.Guid, model.RecodID);
            db.AddInParameter(dbCommand, "DepartID", DbType.Guid, model.DepartID);
            db.AddInParameter(dbCommand, "TermsName", DbType.AnsiString, model.TermsName);
            db.AddInParameter(dbCommand, "ViewPubHouse", DbType.Boolean, model.ViewPubHouse);
            db.AddInParameter(dbCommand, "ViewPrivHouse", DbType.Boolean, model.ViewPrivHouse);
            db.AddInParameter(dbCommand, "ViewHideHouse", DbType.Boolean, model.ViewHideHouse);
            //db.AddInParameter(dbCommand, "ViewPubDemand", DbType.Boolean, model.ViewPubDemand);
            db.AddInParameter(dbCommand, "ViewPrivDemand", DbType.Boolean, model.ViewPrivDemand);
            db.AddInParameter(dbCommand, "ViewRealCustomer", DbType.Boolean, model.ViewRealCustomer);
            db.AddInParameter(dbCommand, "ViewFakeCustomer", DbType.Boolean, model.ViewFakeCustomer);
            db.AddInParameter(dbCommand, "EditPrimaryHouse", DbType.Boolean, model.EditPrimaryHouse);
            db.AddInParameter(dbCommand, "EditNormalHouse", DbType.Boolean, model.EditNormalHouse);
            db.AddInParameter(dbCommand, "DelTrace", DbType.Boolean, model.DelTrace);
            db.AddInParameter(dbCommand, "CanProtect", DbType.Boolean, model.CanProtect);
            db.AddInParameter(dbCommand, "CanLockHouse", DbType.Boolean, model.CanLockHouse);
            db.AddInParameter(dbCommand, "ViewLockHouse", DbType.Boolean, model.ViewLockHouse);
            db.AddInParameter(dbCommand, "ViewChange", DbType.Boolean, model.ViewChange);
            db.AddInParameter(dbCommand, "CanChangeConfirm", DbType.Boolean, model.CanChangeConfirm);
            db.AddInParameter(dbCommand, "ViewEntrust", DbType.Boolean, model.ViewEntrust);
            db.AddInParameter(dbCommand, "CanCancelTrust", DbType.Boolean, model.CanCancelTrust);
            db.AddInParameter(dbCommand, "UnCancelTrust", DbType.Boolean, model.UnCancelTrust);
            db.AddInParameter(dbCommand, "CanDelTrust", DbType.Boolean, model.CanDelTrust);
            db.AddInParameter(dbCommand, "ViewWatching", DbType.Boolean, model.ViewWatching);
            db.AddInParameter(dbCommand, "EditWatching", DbType.Boolean, model.EditWatching);
            db.AddInParameter(dbCommand, "EditKey", DbType.Boolean, model.EditKey);
            db.AddInParameter(dbCommand, "UseKey", DbType.Boolean, model.UseKey);
            db.AddInParameter(dbCommand, "EditKeyUsing", DbType.Boolean, model.EditKeyUsing);
            db.AddInParameter(dbCommand, "EditTrust", DbType.Boolean, model.EditTrust);
            db.AddInParameter(dbCommand, "CancelLockHouse", DbType.Boolean, model.CancelLockHouse);
            //db.AddInParameter(dbCommand, "ViewPubCustomer", DbType.Boolean, model.ViewPubCustomer);
            db.AddInParameter(dbCommand, "ViewPrivCustomer", DbType.Boolean, model.ViewPrivCustomer);
            db.AddInParameter(dbCommand, "EditPubDemand", DbType.Boolean, model.EditPubDemand);
            db.AddInParameter(dbCommand, "EditPrivDemand", DbType.Boolean, model.EditPrivDemand);
            db.AddInParameter(dbCommand, "ViewTelLog", DbType.Boolean, model.ViewTelLog);
            db.AddInParameter(dbCommand, "ViewBusiness", DbType.Boolean, model.ViewBusiness);
            db.AddInParameter(dbCommand, "ViewHrInfo", DbType.Boolean, model.ViewHrInfo);
            db.AddInParameter(dbCommand, "ViewHrChange", DbType.Boolean, model.ViewHrChange);
            db.AddInParameter(dbCommand, "ViewAttendance", DbType.Boolean, model.ViewAttendance);
            db.AddInParameter(dbCommand, "ViewVacation", DbType.Boolean, model.ViewVacation);
            db.AddInParameter(dbCommand, "ViewAnnualLeave", DbType.Boolean, model.ViewAnnualLeave);
            db.AddInParameter(dbCommand, "ViewUserLog", DbType.Boolean, model.ViewUserLog);
            db.AddInParameter(dbCommand, "DelHouse", DbType.Boolean, model.DelHouse);
            db.AddInParameter(dbCommand, "EditPubCustomer", DbType.Boolean, model.EditPubCustomer);
            db.AddInParameter(dbCommand, "EditPrivCustomer", DbType.Boolean, model.EditPrivCustomer);
            db.AddInParameter(dbCommand, "ViewStock", DbType.Boolean, model.ViewStock);
            db.AddInParameter(dbCommand, "IsControl", DbType.Boolean, model.IsControl);
            db.AddInParameter(dbCommand, "Addtime", DbType.DateTime, model.Addtime);
            db.AddInParameter(dbCommand, "ShiftPubCustomer", DbType.Boolean, model.ShiftPubCustomer);
            db.AddInParameter(dbCommand, "SetPubLevel", DbType.Boolean, model.SetPubLevel);
            db.AddInParameter(dbCommand, "ViewCrossPubShareDemand", DbType.Boolean, model.ViewCrossPubShareDemand);
            db.AddInParameter(dbCommand, "ViewPubShareDemand", DbType.Boolean, model.ViewPubShareDemand);
            db.AddInParameter(dbCommand, "ViewCrossPubShareCustomer", DbType.Boolean, model.ViewCrossPubShareCustomer);
            db.AddInParameter(dbCommand, "ViewPubShareCustomer", DbType.Boolean, model.ViewPubShareCustomer);
            db.AddInParameter(dbCommand, "viewtrace", DbType.Boolean, model.ViewTrace);
            db.AddInParameter(dbCommand, "CanUploadPicture", DbType.Boolean, model.CanUploadPicture);
            db.AddInParameter(dbCommand, "CanDeletePicture", DbType.Boolean, model.CanDeletePicture);
            db.AddInParameter(dbCommand, "CanPublishHouse", DbType.Boolean, model.CanPublishHouse);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid RecodID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from HR_Rel_Purview ");
            strSql.Append(" where RecodID=@RecodID ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecodID", DbType.Guid, RecodID);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 根据部门ID得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Hr.Entity.HR_Rel_Purview GetModelByDepId(Guid Depid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecodID,DepartID,TermsName,ViewPubHouse,ViewPrivHouse,ViewHideHouse,ViewPrivDemand,ViewRealCustomer,ViewFakeCustomer,EditPrimaryHouse,EditNormalHouse,DelTrace,CanProtect,CanLockHouse,ViewLockHouse,ViewChange,CanChangeConfirm,ViewEntrust,CanCancelTrust,UnCancelTrust,CanDelTrust,ViewWatching,EditWatching,EditKey,UseKey,EditKeyUsing,EditTrust,CancelLockHouse,ViewPrivCustomer,EditPubDemand,EditPrivDemand,ViewTelLog,ViewBusiness,ViewHrInfo,ViewHrChange,ViewAttendance,ViewVacation,ViewAnnualLeave,ViewUserLog,DelHouse,EditPubCustomer,EditPrivCustomer,ViewStock,IsControl,Addtime,ShiftPubCustomer,SetPubLevel,ViewCrossPubShareDemand,ViewPubShareDemand,ViewCrossPubShareCustomer,ViewPubShareCustomer,viewtrace,CanUploadPicture,CanDeletePicture,CanPublishHouse from HR_Rel_Purview ");
            strSql.Append(" where DepartID=@DepartID ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "DepartID", DbType.Guid, Depid);
            Chenxin.Lib.Hr.Entity.HR_Rel_Purview model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Hr.Entity.HR_Rel_Purview GetModel(Guid RecodID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecodID,DepartID,TermsName,ViewPubHouse,ViewPrivHouse,ViewHideHouse,ViewPrivDemand,ViewRealCustomer,ViewFakeCustomer,EditPrimaryHouse,EditNormalHouse,DelTrace,CanProtect,CanLockHouse,ViewLockHouse,ViewChange,CanChangeConfirm,ViewEntrust,CanCancelTrust,UnCancelTrust,CanDelTrust,ViewWatching,EditWatching,EditKey,UseKey,EditKeyUsing,EditTrust,CancelLockHouse,ViewPrivCustomer,EditPubDemand,EditPrivDemand,ViewTelLog,ViewBusiness,ViewHrInfo,ViewHrChange,ViewAttendance,ViewVacation,ViewAnnualLeave,ViewUserLog,DelHouse,EditPubCustomer,EditPrivCustomer,ViewStock,IsControl,Addtime,ShiftPubCustomer,SetPubLevel,ViewCrossPubShareDemand,ViewPubShareDemand,ViewCrossPubShareCustomer,ViewPubShareCustomer,viewtrace,CanUploadPicture,CanDeletePicture,CanPublishHouse from HR_Rel_Purview ");
            strSql.Append(" where RecodID=@RecodID ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecodID", DbType.Guid, RecodID);
            Chenxin.Lib.Hr.Entity.HR_Rel_Purview model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecodID,DepartID,TermsName,ViewPubHouse,ViewPrivHouse,ViewHideHouse,ViewPrivDemand,ViewRealCustomer,ViewFakeCustomer,EditPrimaryHouse,EditNormalHouse,DelTrace,CanProtect,CanLockHouse,ViewLockHouse,ViewChange,CanChangeConfirm,ViewEntrust,CanCancelTrust,UnCancelTrust,CanDelTrust,ViewWatching,EditWatching,EditKey,UseKey,EditKeyUsing,EditTrust,CancelLockHouse,ViewPrivCustomer,EditPubDemand,EditPrivDemand,ViewTelLog,ViewBusiness,ViewHrInfo,ViewHrChange,ViewAttendance,ViewVacation,ViewAnnualLeave,ViewUserLog,DelHouse,EditPubCustomer,EditPrivCustomer,ViewStock,IsControl,Addtime,ShiftPubCustomer,SetPubLevel,ViewCrossPubShareDemand,ViewPubShareDemand,ViewCrossPubShareCustomer,ViewPubShareCustomer,viewtrace,CanUploadPicture,CanDeletePicture,CanPublishHouse ");
            strSql.Append(" FROM HR_Rel_Purview ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public static DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_House");
            DbCommand dbCommand = db.GetStoredProcCommand("UP_GetRecordByPage");
            db.AddInParameter(dbCommand, "tblName", DbType.AnsiString, "HR_Rel_Purview");
            db.AddInParameter(dbCommand, "fldName", DbType.AnsiString, "ID");
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "IsReCount", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "OrderType", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "strWhere", DbType.AnsiString, strWhere);
            return db.ExecuteDataSet(dbCommand);
        }*/

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Hr.Entity.HR_Rel_Purview> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecodID,DepartID,TermsName,ViewPubHouse,ViewPrivHouse,ViewHideHouse,ViewPrivDemand,ViewRealCustomer,ViewFakeCustomer,EditPrimaryHouse,EditNormalHouse,DelTrace,CanProtect,CanLockHouse,ViewLockHouse,ViewChange,CanChangeConfirm,ViewEntrust,CanCancelTrust,UnCancelTrust,CanDelTrust,ViewWatching,EditWatching,EditKey,UseKey,EditKeyUsing,EditTrust,CancelLockHouse,ViewPrivCustomer,EditPubDemand,EditPrivDemand,ViewTelLog,ViewBusiness,ViewHrInfo,ViewHrChange,ViewAttendance,ViewVacation,ViewAnnualLeave,ViewUserLog,DelHouse,EditPubCustomer,EditPrivCustomer,ViewStock,IsControl,Addtime,ShiftPubCustomer,SetPubLevel,ViewCrossPubShareDemand,ViewPubShareDemand,ViewCrossPubShareCustomer,ViewPubShareCustomer,viewtrace,CanUploadPicture,CanDeletePicture,CanPublishHouse ");
            strSql.Append(" FROM HR_Rel_Purview ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Hr.Entity.HR_Rel_Purview> list = new List<Chenxin.Lib.Hr.Entity.HR_Rel_Purview>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Hr.Entity.HR_Rel_Purview ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Hr.Entity.HR_Rel_Purview model = new Chenxin.Lib.Hr.Entity.HR_Rel_Purview();
            object ojb;
            ojb = dataReader["RecodID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecodID = new Guid(ojb.ToString());
            }
            ojb = dataReader["DepartID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DepartID = new Guid(ojb.ToString());
            }
            model.TermsName = dataReader["TermsName"].ToString();
            ojb = dataReader["ViewPubHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPubHouse = (bool)ojb;
            }
            ojb = dataReader["ViewPrivHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPrivHouse = (bool)ojb;
            }
            ojb = dataReader["ViewHideHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewHideHouse = (bool)ojb;
            }
            //ojb = dataReader["ViewPubDemand"];
            //if (ojb != null && ojb != DBNull.Value)
            //{
            //    model.ViewPubDemand = (bool)ojb;
            //}
            ojb = dataReader["ViewPrivDemand"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPrivDemand = (bool)ojb;
            }
            ojb = dataReader["ViewRealCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewRealCustomer = (bool)ojb;
            }
            ojb = dataReader["ViewFakeCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewFakeCustomer = (bool)ojb;
            }
            ojb = dataReader["EditPrimaryHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditPrimaryHouse = (bool)ojb;
            }
            ojb = dataReader["EditNormalHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditNormalHouse = (bool)ojb;
            }
            ojb = dataReader["DelTrace"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DelTrace = (bool)ojb;
            }
            ojb = dataReader["CanProtect"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanProtect = (bool)ojb;
            }
            ojb = dataReader["CanLockHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanLockHouse = (bool)ojb;
            }
            ojb = dataReader["ViewLockHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewLockHouse = (bool)ojb;
            }
            ojb = dataReader["ViewChange"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewChange = (bool)ojb;
            }
            ojb = dataReader["CanChangeConfirm"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanChangeConfirm = (bool)ojb;
            }
            ojb = dataReader["ViewEntrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewEntrust = (bool)ojb;
            }
            ojb = dataReader["CanCancelTrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanCancelTrust = (bool)ojb;
            }
            ojb = dataReader["UnCancelTrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UnCancelTrust = (bool)ojb;
            }
            ojb = dataReader["CanDelTrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanDelTrust = (bool)ojb;
            }
            ojb = dataReader["ViewWatching"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewWatching = (bool)ojb;
            }
            ojb = dataReader["EditWatching"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditWatching = (bool)ojb;
            }
            ojb = dataReader["EditKey"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditKey = (bool)ojb;
            }
            ojb = dataReader["UseKey"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UseKey = (bool)ojb;
            }
            ojb = dataReader["EditKeyUsing"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditKeyUsing = (bool)ojb;
            }
            ojb = dataReader["EditTrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditTrust = (bool)ojb;
            }
            ojb = dataReader["CancelLockHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CancelLockHouse = (bool)ojb;
            }
            //ojb = dataReader["ViewPubCustomer"];
            //if (ojb != null && ojb != DBNull.Value)
            //{
            //    model.ViewPubCustomer = (bool)ojb;
            //}
            ojb = dataReader["ViewPrivCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPrivCustomer = (bool)ojb;
            }
            ojb = dataReader["EditPubDemand"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditPubDemand = (bool)ojb;
            }
            ojb = dataReader["EditPrivDemand"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditPrivDemand = (bool)ojb;
            }
            ojb = dataReader["ViewTelLog"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewTelLog = (bool)ojb;
            }
            ojb = dataReader["ViewBusiness"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewBusiness = (bool)ojb;
            }
            ojb = dataReader["ViewHrInfo"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewHrInfo = (bool)ojb;
            }
            ojb = dataReader["ViewHrChange"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewHrChange = (bool)ojb;
            }
            ojb = dataReader["ViewAttendance"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewAttendance = (bool)ojb;
            }
            ojb = dataReader["ViewVacation"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewVacation = (bool)ojb;
            }
            ojb = dataReader["ViewAnnualLeave"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewAnnualLeave = (bool)ojb;
            }
            ojb = dataReader["ViewUserLog"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewUserLog = (bool)ojb;
            }
            ojb = dataReader["DelHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DelHouse = (bool)ojb;
            }
            ojb = dataReader["EditPubCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditPubCustomer = (bool)ojb;
            }
            ojb = dataReader["EditPrivCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditPrivCustomer = (bool)ojb;
            }
            ojb = dataReader["ViewStock"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewStock = (bool)ojb;
            }
            ojb = dataReader["IsControl"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsControl = (bool)ojb;
            }
            ojb = dataReader["Addtime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Addtime = (DateTime)ojb;
            }
            ojb = dataReader["ShiftPubCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ShiftPubCustomer = (bool)ojb;
            }
            ojb = dataReader["SetPubLevel"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.SetPubLevel = (bool)ojb;
            }
            ojb = dataReader["ViewCrossPubShareDemand"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewCrossPubShareDemand = (bool)ojb;
            }
            ojb = dataReader["ViewPubShareDemand"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPubShareDemand = (bool)ojb;
            }
            ojb = dataReader["ViewCrossPubShareCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewCrossPubShareCustomer = (bool)ojb;
            }
            ojb = dataReader["ViewPubShareCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPubShareCustomer = (bool)ojb;
            }
            ojb = dataReader["viewtrace"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewTrace = (bool)ojb;
            }
            ojb = dataReader["CanUploadPicture"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanUploadPicture = (bool)ojb;
            }
            ojb = dataReader["CanDeletePicture"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanDeletePicture = (bool)ojb;
            }
            ojb = dataReader["CanPublishHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanPublishHouse = (bool)ojb;
            }
            return model;
        }

        #endregion  成员方法
    }
}

